
//主要界面 分几个界面，家中，出门， 
import { globalType } from "../../../script/util/globalType";
import { PanelInfo } from "../../../script/util/panel/panel";
import { ccs } from "../../../script/util/services";
import { TagsCtrl } from "../../../script/util/tags/tagsCtrl";
import { WinBase } from "../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {
    @property([PanelInfo])
    panelArray: PanelInfo[] = [];

    @property(cc.Sprite)
    panelBgSprite: cc.Sprite = null;

    @property(TagsCtrl)
    tagsCtrl:TagsCtrl = null;

    private _showPanels: globalType.KeyObject<PanelInfo> = {}; //存不同的面板

    private _selectTagKey:string = null; //当前选中的
    
    start () {
        if(this._args.id) {
            ccs.winMgr.showWin("popAlert", {title: " 降生",content: "你从大家的欢呼声中降生到这个世界，你大大的双眼看到了世界的美好，这个世界有太多的东西等待你来探索。",
            cb: () => {
                this.scheduleOnce(() => {
                    ccs.winMgr.showWin('popAlert', {title: "梦想", content: "你会成为默默无闻的路人，还是成为富甲一方的豪强，你3岁时，开始渐渐有了意识，开启了自己的人生之路..."})
                })
            }
        });
        }
        //debugMode 
        this.touchEndEventScale(this.nodes.testBtn, () => {
            ccs.winMgr.showWin("debugWin");
        })
        
        // this.scheduleOnce(() => {
        //     if(ccs.gf.getLocalData("player")){
        //             ccs.gameMgr.loadGame(() => {
        //                 ccs.winMgr.showWin('startWorkWin');
        //             });
        //     }else {
        //         //没有存档
        //         ccs.winMgr.showWin('loginScene');
        //     }
        // },1.5)
        for(let i = 0, len = this.panelArray.length; i < len; i++) {
            let panel = this.panelArray[i];
            this._showPanels[panel.key] = panel;
        }
        this.onTagClick("main");
    }
    
    onSelectKey(key:string) {
        this.tagsCtrl.selectKey(key);
    }
    canClick() {
        return true;
    }
    onTagClick(key:string) {
        console.log('onTagClick', key);
        if(this._selectTagKey) {
            this._showPanels[this._selectTagKey].node.active = false;
        }
        this._selectTagKey = key;
        let panelInfo = this._showPanels[this._selectTagKey];
        if(panelInfo) {
            if(!panelInfo.node) {
                panelInfo.node = cc.instantiate(panelInfo.pfb);
                this.node.addChild(panelInfo.node);
            }
            if(this.panelBgSprite && this.panelBgSprite.spriteFrame) {
                 this.panelBgSprite.spriteFrame = panelInfo.bgSpFrame;
            }
            panelInfo.node.active = true;
            this.updatePanel();
        }
    }

    updatePanel(effectType:number = 0) {
        let panelInfo = this._showPanels[this._selectTagKey];
        // if(panelInfo && panelInfo.node) {
        //     switch(this._selectTagKey) {
        //         case 'bag':
        //             panelInfo.node.getComponent(BagCtrl).updateItems();
        //             break;
        //             case 'role':
        //                 panelInfo.node.getComponent(RoleCtrl).updateInfo();
        //                 break;
        //                 case 'swordtomb':
        //                     panelInfo.node.getComponent(SwordtombCtrl).updateInfo(true, effectType);
        //                     break;
        //                     case 'lifestyle':
        //                         panelInfo.node.getComponent(LifeStyleInfo).updateInfo();
        //                         break;
        //     }
        // }
    }
    // update (dt) {}
}
